<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>系统消息</title>
<link rel="stylesheet"
	href="/static/manage/common/bootstrap/css/bootstrap.min.css" />
<script type="text/javascript"
	src="/static/manage/common/js/jquery-3.2.0.min.js"></script>
<script type="text/javascript"
	src="/static/manage/common/bootstrap/js/bootstrap.min.js"></script>

<link rel="stylesheet"
	href="/static/manage/common/bootstarp-table-1.11.1/bootstrap-table.min.css" />
<script type="text/javascript"
	src="/static/manage/common/bootstarp-table-1.11.1/bootstrap-table.min.js"></script>
<script type="text/javascript"
	src="/static/manage/common/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js"></script>

<script type="text/javascript">
	//转换日期格式(时间戳转换为datetime格式)
	function changeDateFormat(cellval) {
		var dateVal = cellval + "";
		if (cellval != null) {
			var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(
					")/", ""), 10));
			var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1)
					: date.getMonth() + 1;
			var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date
					.getDate();

			var hours = date.getHours() < 10 ? "0" + date.getHours() : date
					.getHours();
			var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes()
					: date.getMinutes();
			var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds()
					: date.getSeconds();

			return date.getFullYear() + "-" + month + "-" + currentDate + " "
					+ hours + ":" + minutes + ":" + seconds;
		}
	}

	//全选
	function checkAll() {
		var qx = document.getElementById("qx");
		var qxson = document.getElementsByClassName("ck");
		for (var i = 0; i < qxson.length; i++) {
			qxson[i].checked = qx.checked
		}
	}

	function checkAll1() {
		var qx1 = document.getElementById("qx1");
		var qxson = document.getElementsByClassName("ck1");
		for (var i = 0; i < qxson.length; i++) {
			qxson[i].checked = qx1.checked
		}
	}

	$(function() {

		//1.初始化Table

		var oTable = new TableInit();

		oTable.Init();

		var message = document.getElementById("message").value;

		if (message != null && message != "") {

			alert(message);

		}
		$("[data-toggle='popover']").popover();

	});

	var TableInit = function() {
		var oTableInit = new Object();
		//初始化Table
		oTableInit.Init = function() {

			$('#t')
					.bootstrapTable(
							{

								method : 'get',

								contentType : "application/x-www-form-urlencoded",

								url : "/manage/weixinGetAll", //请求后台的URL（*）

								striped : true, //是否显示行间隔色

								locale : 'zh-CN', //中文支持

								pagination : true, //是否开启分页（*）

								pageNumber : 1, //初始化加载第一页，默认第一页

								pageSize : 2, //每页的记录行数（*）

								pageList : [ 1, 2, 3 ], //可供选择的每页的行数（*）

								sidePagination : "server", //分页方式：client客户端分页，server服务端分页（*）

								//showRefresh: true, //刷新按钮

								strictSearch : true,

								//showColumns: true, //是否显示所有的列

								minimumCountColumns : 2, //最少允许的列数

								clickToSelect : true, //是否启用点击选中行

								queryParams : queryParams,
								columns : [
										{
											title : '<input type="checkbox"  id="qx" onclick="checkAll()">',
											align : 'center',
											formatter : function(value, row,
													index) {
												return '<input type="checkbox"  class="ck" value="' + row.record_id + '">'
											}
										},
										{
											field : 'username',
											title : '收件人',
											align : 'center'
										},
										{
											field : 'mobile',
											title : '收件人账号',
											align : 'center'
										},
										{
											field : 'content',
											title : '内容',
											align : 'center'
										},
										{
											field : 'send_time',
											title : '发送时间',
											align : 'center',
											formatter : function(value, row,
													index) {
												return changeDateFormat(value)
											}
										} ]

							});

		};

		//得到查询的参数

		function queryParams(params) {//模糊查询

			var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
					//偏移量
					offset: params.offset,

					//每页多少条数据
					pageSize: params.limit,
				"username" : $("#username").val(),
				"mobile" : $("#mobile").val(),
				"content" : $("#content").val(),
				"pay_timestart" : $("#pay_timestart").val(),
				"pay_timeend" : $("#pay_timeend").val()
			};
			return temp;
		}
		;
		return oTableInit;
	};
	function sel() { //刷新
		$("#t").bootstrapTable("refresh")
		$("#record_id").val(""), $("#create_user_id").val("")
	}

	function xuan1() {//选择用户  查bis_custom_user表数据
		$("#tab  tr:not(:first)").html("");
		$
				.ajax({
					type : "get",
					url : "/manage/seleCustUser",
					success : function(data) {
						var a = 0;
						$
								.each(
										data,
										function(index, data) {
											a+=1;
											$("#tab")
													.append(
															'<tr align="center"><td>'
																	+ a
																	+ '</td><td><input type="checkbox"  class="ck1" value='+data.custom_user_id+'></td><td>'
																	+ data.custom_user_id
																	+ '</td><td>'
																	+ data.mobile
																	+ '</td><td>'
																	+ data.username
																	+ '</td><td>'
																	+ data.nikename
																	+ '</td><td>'
																	+ data.sex
																	+ '</td><td>'
																	+ data.openid
																	+ '</td></tr>')
										});
						$("#myModaly").modal('show');
					}
				});

	}

	function add() {//赋值给user框
		var nume = "";
		var yid;
		var qxson = document.getElementsByClassName("ck1");
		for (var i = 0; i < qxson.length; i++) {
			if (qxson[i].checked == true) {
				yid = qxson[i].value
				$("#myModaly").modal('hide');
				nume = nume + yid + ",";
			}
			$("#user").val(nume);
		}

	}

	$(function() {//添加数据
		$("#updatebtn2").click(function() {//发送按钮
			if ($("#user").val() != "") {
				$.ajax({
					type : "get",
					url : "/manage/addWechatRecord",
					data : $("#fm2").serialize(),
					success : function(data) {
						if (data != 0) {
							location.reload();
						}
					}
				})
			} else {
				alert("请选择用户！")
			}
		})

	})

	function dele() {
		var qxson = document.getElementsByClassName("ck");
		if (confirm("确认删除吗")) {
			for (var i = 0; i < qxson.length; i++) {
				if (qxson[i].checked == true) {
					var yid = qxson[i].value
					$.ajax({
						type : "get",
						url : "/manage/delewechatrecord/" + yid,
						data : $("#fm2").serialize(),
						success : function(data) {
							if (data != 0) {
								location.reload();
							}
						}
					});

				}
			}
		} else {
			return;
		}
	}
</script>
</head>

<body>
	<!--系统管理--用户管理界面模糊查询-->
	<form class="form-inline">

		<div class="form-group">
			<label for="account" class="control-label">收件人</label> <input
				type="text" name="record_id" class="form-control" id="username"
				placeholder="请输入记录编号">
		</div>

		<div class="form-group">
			<label for="username">收件人账号：</label> <input type="text"
				name="create_user_id" class="form-control" id="mobile"
				placeholder="请输入收件人账号">
		</div>
		<div class="form-group">
			<label for="username">内容：</label> <input type="text"
				name="create_user_id" class="form-control" id="content"
				placeholder="请输入内容">
		</div>
		<br />
		<div class="form-group">
			<label for="username">发送时间：</label> <input type="date"
				name="pay_timestart" class="form-control" id="pay_timestart"
				placeholder="请输入创建人编号">
		</div>
		<div class="form-group">
			<label for="username">至：</label> <input type="date"
				name="pay_timeend" class="form-control" id="pay_timeend"
				placeholder="请输入创建人编号">
		</div>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<button id="select" type="button" class="btn btn-success"
			onclick="sel()">查询</button>
		<button id="chongzhi" type="reset" class="btn btn-primary">重置</button>
	</form>

	<button class="btn btn-success" data-toggle="modal"
		data-target="#myModal2" id="ssele">发送信息</button>
	<button class="btn btn-warning" onclick="dele()">删除信息</button>
	<form id="fm2">
		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="width: 700px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">发送信息</h4>
					</div>
					<table>
						<tr>
							<td>发送用户：</td>
							<td><input type="text" style="width: 500px; height: 100px;"
								id="user" name="send_user_id" /></td>
							<td>
								<!-- <button type="button" class="btn btn-default"
									aria-label="Left Align">
									
								</button> -->
								<button type="button" class="btn btn-default" id="xuan"
									onclick="xuan1()">
									<span class="glyphicon glyphicon-plus" aria-hidden="true">选择用户</span>
									
									</button> <!-- <button type="reset" class="btn btn">重置</button> -->
							</td>
						</tr>
						<br />
						<tr>
							<td>发送内容 :</td>
							<td ><input type="text"
								style="width: 500px; height: 150px;" id="neirong" name="content" /></td>
							<td>字数小于等于 70 字，按 1 条扣费； 大于将按每 67 字扣 1 条计算</td>
						</tr>
					</table>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="updatebtn2">发送</button>
					</div>
				</div>
			</div>
		</div>
	</form>

	<form id="fm3">
		<div class="modal fade" id="myModaly" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="width: 900px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">选择发送用户</h4>
					</div>
					<div class="table-responsive">
					<table  align="center" id="tab"  class="table table-striped">
						<tr align="center">
						   <td>#</td>
						    <td width="10px"><input type="checkbox" id="qx1" onclick="checkAll1()"></td>
							<td>会员号</td>
							<td>手机号</td>
							<td>姓名</td>
							<td>昵称</td>
							<td>性别</td>
							<td>openid</td>
						</tr>

					</table>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="updatebtn2"
							onclick="add()">添加</button>
					</div>
				</div>
			</div>
		</div>
	</form>

	<table id="t">

	</table>

</body>

</html>
